package Formularios;

import BD.Validacao;
import BD.clientes;
import BD.pedidos;
import BD.pedidos_Itens;
import BD.pizzas;
import BD.utilsPim;
import BD.utilsbd;

import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.w3c.dom.html.HTMLInputElement;

/**
 *
 * @author CORE
 */
public class FormPedidos extends javax.swing.JFrame {
    public String s;
    public String CodPesCli,DesPesCli;
    public int TIPOTELA = 0;// 1 = entrega 2-mesa
    pizzas pizza = new pizzas();

    ArrayList<pizzas> listPizzas = new ArrayList<pizzas>();
    ArrayList<pedidos> listpedidos = new ArrayList<pedidos>();
    utilsPim utlp = new utilsPim();
    utilsbd  utb = new utilsbd();                    
    

    int ponteiro = 0;
    boolean Incluindo = false;
    Validacao vldc = new Validacao();

    /**
     * Creates new form FormPedidos
     */
    public FormPedidos(Integer i) {
        initComponents();
        jtnomecli1.setEditable(false);
        this.TIPOTELA = i;
        TravaBtns(false, true, false);

        setLocationRelativeTo(null);
    }
    private void limpaCampo() {
        this.jtCodPedido.setText("");
        this.jtData6.setDate(null);
        this.jtData1.setText("");
        this.jtNumeroMesa.setText("");
        this.jtValorTotal.setText("");
        this.jtCodcli1.setText("");
        this.jtnomecli1.setText("");
        //this.jcbxclientePesq.setSelectedIndex(-1);
        atualizaTabela(null);

    }

    private boolean Validacao() {
        if (TIPOTELA == 1) {
            if(!vldc.Valida(jtCodcli1.getText(), "Cliente")){
                return  false;
            }else{
                if(utb.checaExiste("clientes","id_clientes='"+jtCodcli1.getText()+"'")){
                  JOptionPane.showMessageDialog(rootPane,"Nenhum cliente encontrado.Verifique!");
                  return  false;
                }else // não pode ter um pedido em aberto com o mesmo cliente ou mesa
                {
                    if(!utb.checaExiste("pedidos","situacao = 'A' and id_clientes='"+jtCodcli1.getText()+"'")){
                      JOptionPane.showMessageDialog(rootPane,"..::ATENÇÃO::.. Já exixte um pedido em aberto para esse cliente.Verifique!");
                      return  false;                        
                    }
                }    
            }    
            return true;
        } else {
            return (vldc.Valida(this.jtNumeroMesa.getText(), "Numero Mesa"));
        }
    }

    private void TravaBtns(boolean incluindo, boolean navegando, boolean pesquisando) {
        jtData6.setVisible(false);
        jtCodPedido.setEditable(false);
        jtValorTotal.setEditable(false);
        jlblCliente.setVisible(TIPOTELA == 1);
        jbtnPesqCli.setVisible(TIPOTELA == 1);
        jtCodcli.setVisible(TIPOTELA == 1);
        jtnomecli.setVisible(TIPOTELA == 1);        
        jtCodcli1.setEditable(incluindo && TIPOTELA == 1);
        jpnlcli.setVisible(TIPOTELA == 1);
        
        jtNumeroMesaPesq.setVisible(TIPOTELA == 2);
        jtNumeroMesa.setVisible(TIPOTELA == 2);
        jlblcodmesa.setVisible(TIPOTELA == 2);
        jtNumeroMesa.setEnabled(TIPOTELA == 2 && incluindo);
        
        jtData1.setEditable(false);
        jtData1.setVisible(! incluindo);
        jpcodigo.setVisible(navegando);
        if (TIPOTELA == 1) {
            jlblPesq.setText("Cliente:");
        } else {
            jlblPesq.setText("Nº Mesa:");
        }

        jtNumeroMesa.setEditable(incluindo);
        jpnlPesq.setVisible(!incluindo && navegando);
        jPnlItens.setVisible(!incluindo && navegando);
        if (incluindo) {
            jbtncancelar.setVisible(true);
            jbtnGravar.setVisible(true);
            jpnlPesq.setVisible(false);
            jbtnexcluir.setVisible(false);
            jbtnNovo.setVisible(false);
            jPnlItens.setVisible(false);
        } else if (navegando) {
            jbtncancelar.setVisible(false);
            jbtnGravar.setVisible(false);
            jpnlPesq.setVisible(true);
            jbtnexcluir.setVisible(true);
            jbtnNovo.setVisible(true);
            jPnlItens.setVisible(true);
        }
    }

    private void movPonteiro(boolean first, boolean prior, boolean next, boolean last) {

        if (listpedidos.size() > 0) {
            if (first) {
                this.ponteiro = 0;
            } else if (prior) {
                this.ponteiro = this.ponteiro - 1;
                if (this.ponteiro < 0) {
                    this.ponteiro = 0;
                }
            } else if (next) {
                this.ponteiro = this.ponteiro + 1;
                if (this.ponteiro > (listpedidos.size() - 1)) {
                    this.ponteiro = (listpedidos.size() - 1);
                }
            } else if (last) {
                this.ponteiro = (listpedidos.size() - 1);
            }

            this.jtCodPedido.setText(Integer.toString(listpedidos.get(this.ponteiro).getId_pedidos()));
            this.jtNumeroMesa.setText(Integer.toString(listpedidos.get(this.ponteiro).getMesa()));
            this.jtData6.setDate(listpedidos.get(this.ponteiro).getData());

            this.jtCodcli1.setText(Integer.toString(listpedidos.get(this.ponteiro).getId_clientes()));
            if(!this.jtCodcli1.getText().equals(""))
                jtCodcli1FocusLost(null);                

            
            jtData1.setText(utlp.getDateHoraChooser(jtData6));

            atualizaTabela(listpedidos.get(ponteiro).getListitens());

        } else {
            limpaCampo();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpnlPesq = new javax.swing.JPanel();
        jlblPesq = new javax.swing.JLabel();
        jtNumeroMesaPesq = new javax.swing.JTextField();
        jbtnPesquisa = new javax.swing.JButton();
        jpNavegacao3 = new javax.swing.JPanel();
        jbtnFirst = new javax.swing.JButton();
        jbtnPrior = new javax.swing.JButton();
        jbtnNext = new javax.swing.JButton();
        jbtnLast = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jtCodcli = new javax.swing.JTextField();
        jlblPesq1 = new javax.swing.JLabel();
        jtnomecli = new javax.swing.JTextField();
        jbtnPesqCli = new javax.swing.JButton();
        jpn = new javax.swing.JPanel();
        jlblcodmesa = new javax.swing.JLabel();
        jlblCliente = new javax.swing.JLabel();
        jtNumeroMesa = new javax.swing.JTextField();
        jPnlItens = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jbtnNovoItem = new javax.swing.JButton();
        jbtnexcluirItem = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jtValorTotal = new javax.swing.JTextField();
        jtData6 = new com.toedter.calendar.JDateChooser();
        jpcodigo = new javax.swing.JPanel();
        jtCodPedido = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jtData1 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jpnlcli = new javax.swing.JPanel();
        jtnomecli1 = new javax.swing.JTextField();
        jbtnPesqCli1 = new javax.swing.JButton();
        jtCodcli1 = new javax.swing.JTextField();
        jbtnNovo = new javax.swing.JButton();
        jbtnGravar = new javax.swing.JButton();
        jbtnexcluir = new javax.swing.JButton();
        jbtncancelar = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Master Pizza - Pedidos");

        jlblPesq.setText("Nº Mesa");

        jtNumeroMesaPesq.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtNumeroMesaPesqKeyTyped(evt);
            }
        });

        jbtnPesquisa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Pesquisa.png"))); // NOI18N
        jbtnPesquisa.setText("Pesquisar");
        jbtnPesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnPesquisaActionPerformed(evt);
            }
        });

        jbtnFirst.setText("<<");
        jbtnFirst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnFirstActionPerformed(evt);
            }
        });

        jbtnPrior.setText("<");
        jbtnPrior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnPriorActionPerformed(evt);
            }
        });

        jbtnNext.setText(">");
        jbtnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNextActionPerformed(evt);
            }
        });

        jbtnLast.setText(">>");
        jbtnLast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnLastActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpNavegacao3Layout = new javax.swing.GroupLayout(jpNavegacao3);
        jpNavegacao3.setLayout(jpNavegacao3Layout);
        jpNavegacao3Layout.setHorizontalGroup(
            jpNavegacao3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNavegacao3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtnFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnPrior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnLast)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jpNavegacao3Layout.setVerticalGroup(
            jpNavegacao3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpNavegacao3Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jpNavegacao3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnFirst)
                    .addComponent(jbtnPrior)
                    .addComponent(jbtnNext)
                    .addComponent(jbtnLast)))
        );

        jtCodcli.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtCodcliFocusLost(evt);
            }
        });
        jtCodcli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtCodcliKeyTyped(evt);
            }
        });

        jbtnPesqCli.setText("...");
        jbtnPesqCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnPesqCliActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpnlPesqLayout = new javax.swing.GroupLayout(jpnlPesq);
        jpnlPesq.setLayout(jpnlPesqLayout);
        jpnlPesqLayout.setHorizontalGroup(
            jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator3)
            .addGroup(jpnlPesqLayout.createSequentialGroup()
                .addGroup(jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnlPesqLayout.createSequentialGroup()
                        .addGap(78, 78, 78)
                        .addComponent(jlblPesq1))
                    .addGroup(jpnlPesqLayout.createSequentialGroup()
                        .addGap(144, 144, 144)
                        .addComponent(jpNavegacao3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jpnlPesqLayout.createSequentialGroup()
                    .addGap(511, 511, 511)
                    .addComponent(jSeparator1))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnlPesqLayout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jlblPesq)
                        .addGroup(jpnlPesqLayout.createSequentialGroup()
                            .addComponent(jtNumeroMesaPesq, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jtCodcli, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jbtnPesqCli, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jtnomecli, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jbtnPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap()))
        );
        jpnlPesqLayout.setVerticalGroup(
            jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlPesqLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlblPesq1)
                .addGap(12, 12, 12)
                .addComponent(jlblPesq)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtCodcli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtnomecli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnPesquisa)
                    .addComponent(jtNumeroMesaPesq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnPesqCli))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpNavegacao3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jlblcodmesa.setText("Numero da Mesa");

        jlblCliente.setText("Cliente");

        jtNumeroMesa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtNumeroMesaKeyTyped(evt);
            }
        });

        jLabel6.setText("Descrição do Pedido");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Tipo", "ID", "Pizza Sabor / Bebida Descricao", "Tm/Vl", "Valor"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setCellSelectionEnabled(true);
        jTable1.getTableHeader().setReorderingAllowed(false);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable1);
        jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        if (jTable1.getColumnModel().getColumnCount() > 0) {
            jTable1.getColumnModel().getColumn(0).setMaxWidth(50);
            jTable1.getColumnModel().getColumn(1).setMaxWidth(50);
            jTable1.getColumnModel().getColumn(2).setMaxWidth(500);
            jTable1.getColumnModel().getColumn(3).setMaxWidth(50);
            jTable1.getColumnModel().getColumn(4).setMaxWidth(100);
        }

        jbtnNovoItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Incluir.png"))); // NOI18N
        jbtnNovoItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNovoItemActionPerformed(evt);
            }
        });

        jbtnexcluirItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Excluir.png"))); // NOI18N
        jbtnexcluirItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnexcluirItemActionPerformed(evt);
            }
        });

        jLabel7.setText("Valor Total");

        jtValorTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtValorTotalActionPerformed(evt);
            }
        });
        jtValorTotal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtValorTotalKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPnlItensLayout = new javax.swing.GroupLayout(jPnlItens);
        jPnlItens.setLayout(jPnlItensLayout);
        jPnlItensLayout.setHorizontalGroup(
            jPnlItensLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
            .addGroup(jPnlItensLayout.createSequentialGroup()
                .addComponent(jLabel6)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPnlItensLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtnNovoItem, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnexcluirItem)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPnlItensLayout.setVerticalGroup(
            jPnlItensLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlItensLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPnlItensLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnNovoItem)
                    .addComponent(jbtnexcluirItem)
                    .addComponent(jtValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addContainerGap())
        );

        jtData6.setDateFormatString("dd/MM/yyyy HH:mm");

        jLabel1.setText("Código Pedido");

        jLabel5.setText("Data");

        javax.swing.GroupLayout jpcodigoLayout = new javax.swing.GroupLayout(jpcodigo);
        jpcodigo.setLayout(jpcodigoLayout);
        jpcodigoLayout.setHorizontalGroup(
            jpcodigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpcodigoLayout.createSequentialGroup()
                .addGroup(jpcodigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1)
                    .addComponent(jtCodPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpcodigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpcodigoLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(0, 264, Short.MAX_VALUE))
                    .addGroup(jpcodigoLayout.createSequentialGroup()
                        .addComponent(jtData1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        jpcodigoLayout.setVerticalGroup(
            jpcodigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpcodigoLayout.createSequentialGroup()
                .addGroup(jpcodigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpcodigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtCodPedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtData1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jbtnPesqCli1.setText("...");
        jbtnPesqCli1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnPesqCli1ActionPerformed(evt);
            }
        });

        jtCodcli1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtCodcli1FocusLost(evt);
            }
        });

        javax.swing.GroupLayout jpnlcliLayout = new javax.swing.GroupLayout(jpnlcli);
        jpnlcli.setLayout(jpnlcliLayout);
        jpnlcliLayout.setHorizontalGroup(
            jpnlcliLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlcliLayout.createSequentialGroup()
                .addComponent(jtCodcli1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnPesqCli1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtnomecli1, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jpnlcliLayout.setVerticalGroup(
            jpnlcliLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlcliLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jtCodcli1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jtnomecli1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jbtnPesqCli1))
        );

        javax.swing.GroupLayout jpnLayout = new javax.swing.GroupLayout(jpn);
        jpn.setLayout(jpnLayout);
        jpnLayout.setHorizontalGroup(
            jpnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnLayout.createSequentialGroup()
                        .addGroup(jpnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPnlItens, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jpnLayout.createSequentialGroup()
                                .addGroup(jpnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jlblcodmesa)
                                    .addComponent(jlblCliente))
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(jpnLayout.createSequentialGroup()
                                .addComponent(jtNumeroMesa, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jpnlcli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addContainerGap())
                    .addGroup(jpnLayout.createSequentialGroup()
                        .addComponent(jpcodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jtData6, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32))))
        );
        jpnLayout.setVerticalGroup(
            jpnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jpcodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtData6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblcodmesa)
                    .addComponent(jlblCliente))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtNumeroMesa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jpnlcli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPnlItens, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jbtnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Incluir.png"))); // NOI18N
        jbtnNovo.setText("Novo");
        jbtnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNovoActionPerformed(evt);
            }
        });

        jbtnGravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Gravar.png"))); // NOI18N
        jbtnGravar.setText("Gravar");
        jbtnGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnGravarActionPerformed(evt);
            }
        });

        jbtnexcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Excluir.png"))); // NOI18N
        jbtnexcluir.setText("Excluir");
        jbtnexcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnexcluirActionPerformed(evt);
            }
        });

        jbtncancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Cancelar.png"))); // NOI18N
        jbtncancelar.setText("Cancelar");
        jbtncancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtncancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator2)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtnNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnGravar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnexcluir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtncancelar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jpn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jpnlPesq, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jpnlPesq, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jpn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtncancelar)
                    .addComponent(jbtnexcluir)
                    .addComponent(jbtnGravar)
                    .addComponent(jbtnNovo))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnPesquisaActionPerformed
        pedidos ped = new pedidos();
        ped.setSiuacao("A");
        ped.TipoTela =TIPOTELA;
        if (TIPOTELA == 1) {
            if (! jtnomecli.getText().equals("")) 
                ped.setCliente_nome(jtnomecli.getText());
            if (! jtCodcli.getText().equals("")) 
                ped.setId_clientes(Integer.parseInt(jtCodcli.getText()));
        } else {
            if (!jtNumeroMesaPesq.getText().equals("")) {
                ped.setMesa(Integer.parseInt(jtNumeroMesaPesq.getText()));
            } else {
                ped.TipoTela = 2;
            }
        }
        listpedidos = ped.getItens();         // TODO add your handling code here:
        TravaBtns(false, true, true);
        jbtnFirstActionPerformed(evt);
        if (listpedidos.size() <= 0) {
            JOptionPane.showMessageDialog(null, "Nenhum registro encontrado na pesquiza");
        }
    }//GEN-LAST:event_jbtnPesquisaActionPerformed

    private void jbtnFirstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnFirstActionPerformed
        movPonteiro(true, false, false, false);
    }//GEN-LAST:event_jbtnFirstActionPerformed

    private void jbtnPriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnPriorActionPerformed
        movPonteiro(false, true, false, false);
    }//GEN-LAST:event_jbtnPriorActionPerformed

    private void jbtnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNextActionPerformed
        movPonteiro(false, false, true, false);
    }//GEN-LAST:event_jbtnNextActionPerformed

    private void jbtnLastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnLastActionPerformed
        movPonteiro(false, false, false, true);
    }//GEN-LAST:event_jbtnLastActionPerformed

    private void jbtnNovoItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNovoItemActionPerformed
        if(listpedidos.size() <= 0){
            if(TIPOTELA == 1)
                JOptionPane.showMessageDialog(null,"Informe o cliente por favor " );
            else
                JOptionPane.showMessageDialog(null,"Informe o numero da mesa por favor " );
                
            jbtnNovoActionPerformed(evt);
            return;
        }
        System.out.println(listpedidos.size() + "FormePedido");            
        CarregaSelecionador(true);
    }//GEN-LAST:event_jbtnNovoItemActionPerformed
    private void CarregaSelecionador(boolean MostrarSelecionador) {
        pedidos pd = new pedidos();        
        /*if (TIPOTELA == 1) {
            pd.setId_clientes(jtCodcli1.getText().hashCode());
        } else {
            if(! jtNumeroMesa.getText().equals("") ) 
              pd.setMesa(Integer.parseInt(jtNumeroMesa.getText()));
        }*/

        pd.setId_pedidos(Integer.parseInt(jtCodPedido.getText()));
        this.listpedidos = pd.getItens();
        //carrega o selecionador de pizzas   
        if (MostrarSelecionador) {
            SelecionaPedidos_itens sle = new SelecionaPedidos_itens(this, true);
            sle.setId_pedidos(listpedidos.get(0).getId_pedidos());
            sle.setModal(true);
            sle.setVisible(true);
        }
        // apos o selecionar fdechar tem que carregar os itens do pedido novamente
        listpedidos = pd.getItens();//atuzaliza
        atualizaTabela(listpedidos.get(0).getListitens());
        //listpedidos = listpedidos;

    }

    private void atualizaTabela(ArrayList<pedidos_Itens> lstpd) {
        DefaultTableModel modeloTabela = (DefaultTableModel) jTable1.getModel();
        while (jTable1.getRowCount() > 0) {
            modeloTabela.removeRow(0);
        }
        jtValorTotal.setText("");
        if (lstpd != null) {
            int lin = 0;

            float valorTt = 0;
                for (int j = 0; j < lstpd.size(); j++) {
                    modeloTabela.addRow(new String[modeloTabela.getColumnCount()]);//adciona linha            

                    if (lstpd.get(j).getId_pizzas() > 0) {
                        jTable1.setValueAt("PIZZ", lin, 0);
                        jTable1.setValueAt(lstpd.get(j).getPizzas().getDesc_sabor(), lin, 2);
                        jTable1.setValueAt(lstpd.get(j).getPizzas().getTamanho(), lin, 3);
                    } else {
                        jTable1.setValueAt("BEBI", lin, 0);
                        jTable1.setValueAt(lstpd.get(j).getProdutos().getDescricao(), lin, 2);
                        jTable1.setValueAt(lstpd.get(j).getProdutos().getVolume(), lin, 3);

                    }
                    jTable1.setValueAt(lstpd.get(j).getId_pedido_itens(), lin, 1);
                    jTable1.setValueAt(utlp.formatavalor(lstpd.get(j).getValor()), lin, 4);
                    valorTt = valorTt + lstpd.get(j).getValor();
                    lin = lin + 1;
                }
            
            jtValorTotal.setText(utlp.formatavalor(valorTt));
        }

    }
    private void jbtnexcluirItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnexcluirItemActionPerformed
        // TODO add your handling code here:
        if(listpedidos.size() <=0){
            JOptionPane.showMessageDialog(null, "Nenhum registro encontrado. Verifique!");
            return;
        }           
        if(jTable1.getSelectedRow() < 0){
            JOptionPane.showMessageDialog(null, "Favor selecione um item do pedido");
            return;
            
        }    
        DefaultTableModel modeloTabela = (DefaultTableModel) jTable1.getModel();
        while (jTable1.getSelectedRow() > (-1)) {
            pedidos_Itens pdi = new pedidos_Itens();
            pdi.setId_pedido_itens(jTable1.getValueAt(jTable1.getSelectedRow(), 1).hashCode());
            if (pdi.excluir()) {
                modeloTabela.removeRow(jTable1.getSelectedRow());
            } else {
                JOptionPane.showMessageDialog(rootPane, "Erro de exlusão do item");
            }
        }
        CarregaSelecionador(false);

    }//GEN-LAST:event_jbtnexcluirItemActionPerformed

    private void jbtnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNovoActionPerformed
        Incluindo = true;
        TravaBtns(true, false, false);
        limpaCampo();

    }//GEN-LAST:event_jbtnNovoActionPerformed

    private void jbtnGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnGravarActionPerformed
        if (Validacao()) {
            pedidos ped = new pedidos();
            if (TIPOTELA == 1) {
                ped.setId_clientes(Integer.parseInt(jtCodcli1.getText()));
            } else {
                ped.setMesa(Integer.parseInt(this.jtNumeroMesa.getText()));
                jtNumeroMesaPesq.setText(this.jtNumeroMesa.getText());
            }
            if (Incluindo) {
                if (ped.incluir()) {
                    TravaBtns(false, true, false);
                    JOptionPane.showMessageDialog(null, "Operação bem sucedida");
                    jtCodcli.setText(Integer.toString(ped.getId_clientes()));
                    jbtnPesquisaActionPerformed(evt);

                } else {
                    JOptionPane.showMessageDialog(null, "Erro ao incluir produtos");
                }
            } else {
                ped.setId_pedidos(Integer.parseInt(this.jtCodPedido.getText()));

                if (ped.alterar()) {
                    JOptionPane.showMessageDialog(null, "Operação bem sucedida");
                } else {
                    JOptionPane.showMessageDialog(null, "Erro ao alterar produtos");
                }
            }

        }
    }//GEN-LAST:event_jbtnGravarActionPerformed

    private void jbtnexcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnexcluirActionPerformed

        if (listpedidos.size() <= 0) {
            JOptionPane.showMessageDialog(null, "Nenhum registro Encontrado");
        } else {
            String Texto = "";
            if (TIPOTELA == 1) {
                Texto = " do cliente: " + jtnomecli1.getText();
            } else {
                Texto = " da mesa:" + jtNumeroMesa.getText();
            }

            if (JOptionPane.showConfirmDialog(null, "Deseja exluir o pedido " + Texto) == 0) {
                if (listpedidos.get(ponteiro).excluir()) {
                    JOptionPane.showMessageDialog(null, "Operação bem sucedida");
                    limpaCampo();
//                    jbtnPesquisaActionPerformed(evt);
                } else {
                    JOptionPane.showMessageDialog(null, "Erro ao excluir produto");
                }
            }
        }
    }//GEN-LAST:event_jbtnexcluirActionPerformed

    private void jbtncancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtncancelarActionPerformed
        Incluindo = false;
        TravaBtns(false, true, false);
        limpaCampo();
    }//GEN-LAST:event_jbtncancelarActionPerformed

    private void jtValorTotalKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtValorTotalKeyTyped
//        String caracteres = "0987654321";
//        if (!caracteres.contains(evt.getKeyChar() + "")) {
        evt.consume();
//        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jtValorTotalKeyTyped

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 2) {
            jbtnexcluirItemActionPerformed(null);
        }

    }//GEN-LAST:event_jTable1MouseClicked

    private void jtValorTotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtValorTotalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtValorTotalActionPerformed

    private void jtNumeroMesaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtNumeroMesaKeyTyped
        String caracteres = "0987654321";
        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_jtNumeroMesaKeyTyped

    private void jbtnPesqCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnPesqCliActionPerformed
        // TODO add your handling code here:
        FormPesqcliente fpc = new FormPesqcliente(this, true);
        fpc.fp = this;
        fpc.setVisible(true);
        
        jtCodcli.setText(CodPesCli);
        jtnomecli.setText(DesPesCli);        
        jbtnPesquisaActionPerformed(evt);
    }//GEN-LAST:event_jbtnPesqCliActionPerformed

    private void jbtnPesqCli1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnPesqCli1ActionPerformed
        FormPesqcliente fpc = new FormPesqcliente(this, true);
        fpc.fp = this;
        fpc.setVisible(true);
        
        jtCodcli1.setText(CodPesCli);
        jtnomecli1.setText(DesPesCli);        
        jtCodcli1FocusLost(null);


    }//GEN-LAST:event_jbtnPesqCli1ActionPerformed

    private void jtNumeroMesaPesqKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtNumeroMesaPesqKeyTyped
        String caracteres = "0987654321";
        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jtNumeroMesaPesqKeyTyped

    private void jtCodcliKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtCodcliKeyTyped
        // TODO add your handling code here:
        jtNumeroMesaPesqKeyTyped(evt);
    }//GEN-LAST:event_jtCodcliKeyTyped

    private void jtCodcli1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtCodcli1FocusLost
        if(! jtCodcli1.getText().equals("")){
//              if(cli.getItens().size() > 0 && cli.getItens().get(0).getId_cliente() == Integer.parseInt(jtCodcli1.getText()) )
            if(!utb.checaExiste("clientes","id_clientes='"+jtCodcli1.getText()+"'")){
              clientes cli = new clientes();
              cli.setId_cliente(Integer.parseInt(jtCodcli1.getText()));
              jtnomecli1.setText(cli.getItens().get(0).getNome());
            }else
              jtnomecli1.setText("Nenhum cliente");               
        }else            
          jtnomecli1.setText("Nenhum cliente");               
//        System.out.println(cli.getId_cliente());
                    
        //}
    }//GEN-LAST:event_jtCodcli1FocusLost

    private void jtCodcliFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtCodcliFocusLost
        if(! jtCodcli1.getText().equals("")){
//              if(cli.getItens().size() > 0 && cli.getItens().get(0).getId_cliente() == Integer.parseInt(jtCodcli1.getText()) )
            if(!utb.checaExiste("clientes","id_clientes='"+jtCodcli1.getText()+"'")){
              clientes cli = new clientes();
              cli.setId_cliente(Integer.parseInt(jtCodcli1.getText()));
              jtnomecli1.setText(cli.getItens().get(0).getNome());
            }else
              jtnomecli1.setText("");               
        }else            
          jtnomecli1.setText("");               
        // TODO add your handling code here:
    }//GEN-LAST:event_jtCodcliFocusLost

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
//                if ("Windowns".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormPedidos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormPedidos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormPedidos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormPedidos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

                new FormPedidos(1).setVisible(true);

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPnlItens;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton jbtnFirst;
    private javax.swing.JButton jbtnGravar;
    private javax.swing.JButton jbtnLast;
    private javax.swing.JButton jbtnNext;
    private javax.swing.JButton jbtnNovo;
    private javax.swing.JButton jbtnNovoItem;
    private javax.swing.JButton jbtnPesqCli;
    private javax.swing.JButton jbtnPesqCli1;
    private javax.swing.JButton jbtnPesquisa;
    private javax.swing.JButton jbtnPrior;
    private javax.swing.JButton jbtncancelar;
    private javax.swing.JButton jbtnexcluir;
    private javax.swing.JButton jbtnexcluirItem;
    private javax.swing.JLabel jlblCliente;
    private javax.swing.JLabel jlblPesq;
    private javax.swing.JLabel jlblPesq1;
    private javax.swing.JLabel jlblcodmesa;
    private javax.swing.JPanel jpNavegacao3;
    private javax.swing.JPanel jpcodigo;
    private javax.swing.JPanel jpn;
    private javax.swing.JPanel jpnlPesq;
    private javax.swing.JPanel jpnlcli;
    private javax.swing.JTextField jtCodPedido;
    private javax.swing.JTextField jtCodcli;
    private javax.swing.JTextField jtCodcli1;
    private javax.swing.JTextField jtData1;
    private com.toedter.calendar.JDateChooser jtData6;
    private javax.swing.JTextField jtNumeroMesa;
    private javax.swing.JTextField jtNumeroMesaPesq;
    private javax.swing.JTextField jtValorTotal;
    private javax.swing.JTextField jtnomecli;
    private javax.swing.JTextField jtnomecli1;
    // End of variables declaration//GEN-END:variables
}
